package com.yqg.manage.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yqg.manage.common.interceptor.SysLog;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.manage.common.Result;

import com.yqg.manage.service.ILawsAndRegulationsService;
import com.yqg.manage.entity.LawsAndRegulations;

import org.springframework.web.bind.annotation.RestController;

/**
 * LawsAndRegulationsController 前端控制器
 *
 * @author zxf
 * @since 2025-07-26
 */
@RestController
@RequestMapping("/laws-and-regulations")
public class LawsAndRegulationsController {

    @Resource
    private ILawsAndRegulationsService lawsAndRegulationsService;

    /**
     * 新增或者更新
     */
    @PostMapping("/edit")
    @SysLog("新增或者更新违法行为")
    public Result save(@RequestBody LawsAndRegulations lawsAndRegulations) {
        return Result.success(lawsAndRegulationsService.edit(lawsAndRegulations));
    }

    /**
     * 删除
     */
    @GetMapping("delete/{id}")
    @SysLog("删除违法行为")
    public Result delete(@PathVariable Integer id) {
        LawsAndRegulations lawsAndRegulations = lawsAndRegulationsService.getById(id);
        lawsAndRegulations.setIsDelete("1");
        return Result.success(lawsAndRegulationsService.saveOrUpdate(lawsAndRegulations));
    }

    /**
     * 查询所有
     */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<LawsAndRegulations> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        List<LawsAndRegulations> list = lawsAndRegulationsService.list(queryWrapper);
        return Result.success(list);
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(lawsAndRegulationsService.getById(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam String search) {
        Map<String,Object> map = lawsAndRegulationsService.getLawsAndRegulationsList(pageNum,pageSize,search);
        return Result.success(map);
    }
    /**
     * 编辑时获取法律条款对象列表
     */
    @GetMapping("/getTermObjectList")
    public Result getTermObjectList(@RequestParam List<Integer> illegalTermsIds,
                                    @RequestParam List<Integer> illegalBasisIds){
        Map<String,Object> map = lawsAndRegulationsService.getTermObjectList(illegalTermsIds,illegalBasisIds);
        return Result.success(map);
    }
}

